package com.example.tccdemo.service;

import com.example.tccdemo.db132.dao.OrderMapper;
import com.example.tccdemo.db132.model.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @describte:订单操作
 * @program:distribute-transaction
 * @author:zhengdp
 * @create:2021-09-26 22:20:05
 **/
@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

    /**
     * 修改订单状态 （订单回调接口）
     * @param orderId 订单Id
     * @return 1:订单不存在 0:更新成功
     */
    public int handleOrder(int orderId){
        Order order = orderMapper.selectByPrimaryKey(orderId);
        if(order == null){
            return 1;
        }
        // 设置为已支付
        order.setOrderStatus(1);
        order.setUpdateTime(new Date());
        order.setUpdateUser(0); // 0 标识系统更新
        orderMapper.updateByPrimaryKey(order);
        return 0;
    }
}
